package com.xopencode.spring;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.PayloadApplicationEvent;
import org.springframework.context.event.ApplicationEventMulticaster;
import org.springframework.stereotype.Component;

/**
 * @Auther: Mcb
 * @Date: 2022/3/1 23:53
 * @Description: 通过注入方式，使用applicationEventMulticaster发布事件
 */
@Component
public class PublishService {

    @Autowired
    private ApplicationEventMulticaster applicationEventMulticaster;

    public void publish(){
        System.out.println("事件发布");
        applicationEventMulticaster.multicastEvent(new PayloadApplicationEvent<String>(this,"事件信息"));
    }
}
